home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample PMSAM / PMSAM Framework / Common / CRecordID.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  7.2 KB  |  257 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CRecordID.h
  3.  
  4.     Contains:    Copied and modified from Admin sources
  5.  
  6.     Written by:    Tim Harnett
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <9>     2/27/95    TMH        adapt to use ETO16 universal headers
  13.          <8>     2/21/95    TMH        metrowerks changes don't use duplicate arg name
  14.          <7>     2/17/95    TMH        added CRecordID(short pcatDSRefNum,StringPtr recName,StringPtr
  15.                                     recType)
  16.          <6>     2/14/95    CL        remove globls
  17.          <5>    10/18/94    TMH        added PackKeyChainRID
  18.          <4>    10/14/94    TMH        added CRLI constructor
  19.          <3>    10/13/94    TMH        added GetDiscriminator etc.
  20.          <2>    10/11/94    TMH        added CRecordID(short pcatDSRefNum,char* recName,char* recType)
  21.          <1>     9/20/94    TMH        Abandon RoadsideRest embrace Mercury
  22.          <2>     6/14/94    TMH        added RecordID* rid assignment operator
  23.                   4/5/94    TMH        xxx put comment here xxx
  24.  
  25.     To Do:
  26. */
  27.  
  28.  
  29. #ifndef __CRecordID__
  30. #define __CRecordID__
  31.  
  32.  
  33. #ifndef        __BaseTypes__
  34. #include    "BaseTypes.h"
  35. #endif
  36.  
  37. #ifndef        __CRString__
  38. #include    "CRString.h"
  39. #endif
  40.  
  41.  
  42.  
  43. //------------------------------------------
  44. //            C R L I 
  45. //--------------------------------------------
  46.  
  47.  
  48. class CRLI {
  49. public:
  50.     CDirectoryName*        fDirName;
  51.     DirDiscriminator    fDiscriminator;
  52.     DNodeNum            fDNodeNumber;
  53.     PackedPathNamePtr    fPackedPath;
  54.     
  55.     CRLI(char* dirName,OSType signature, long dirMisc= 0);
  56.     CRLI(StringPtr dirName,OSType signature, long dirMisc= 0);
  57.     CRLI(CDirectoryName& dirName,DirDiscriminator& dirDisc);
  58. private:
  59.     void                Initialize();
  60.  
  61.     CDirectoryName        _fDirName;
  62. };
  63.  
  64. inline void CRLI::Initialize()
  65. {
  66.     memset(this,0,sizeof(CRLI));
  67.     fDirName = &_fDirName;
  68. }
  69.  
  70. inline CRLI::CRLI(CDirectoryName& dirName,DirDiscriminator& dirDisc)
  71. {
  72.     this->Initialize();
  73.     
  74.     _fDirName = dirName; 
  75.     fDiscriminator.signature = dirDisc.signature;
  76.     fDiscriminator.misc = dirDisc.misc;
  77. }
  78.  
  79. inline CRLI::CRLI(char* dirName,OCEDirectoryKind signature, long dirMisc)
  80. {
  81.     this->Initialize();
  82.     
  83.     _fDirName = dirName; 
  84.     
  85.     fDiscriminator.signature = signature;
  86.     fDiscriminator.misc = dirMisc;
  87.     
  88.     
  89. }
  90.  
  91. inline CRLI::CRLI(StringPtr dirName,OCEDirectoryKind signature, long dirMisc)
  92. {
  93.     this->Initialize();
  94.     _fDirName = dirName; 
  95.  
  96.     fDiscriminator.signature = signature;
  97.     fDiscriminator.misc = dirMisc;
  98. }
  99.  
  100.  
  101. //------------------------------------------------------------------------
  102. //                    C P a c k e d R L I
  103. //-------------------------------------------------------------------------
  104.  
  105.  
  106. //        DO NOT USE FOR PATHNAMES RLI FORM!!!
  107. //         Implements ONLY The dnode number form.
  108. //
  109. //
  110. //        Personal Catalog Note:  Because a record can be references with only
  111. //        a dsRefNum; a full RLI is not neccessary.  The PCAT form hold only the 
  112. //        dsRefNum.
  113. //
  114. //        TBD: some accessors.  PCAT RLI's are not supported. 
  115. //
  116. //----------------------------------------------------------------------------
  117.  
  118. class CPackedRLI {
  119.     friend    class    CRecordID;
  120. public:
  121.     
  122.     unsigned short        fLength;                //    length of the packed RLI excluding length field
  123.     DNodeNum            fNodeNumber;            //    dNodeNumber of the cluster
  124.     CDirectoryName        fDirectoryName;            //    var length
  125.     DirDiscriminator    fDiscriminator;            //    packed after the fDirName. 
  126.     short                fPackedPathNameLen;    
  127.         
  128. private:
  129.     short                fDSRefNum;                //     
  130.  
  131. public:
  132.     CPackedRLI() {fDSRefNum = 0;};
  133.     CPackedRLI& operator =(RLI* rli);
  134.     CPackedRLI& operator =(CRLI& rli);
  135.     
  136.     
  137.         //    So we do assignment to OCE.h defined fields.
  138.     operator PackedRLI*() { return (PackedRLI*) this; };
  139.     operator const PackedRLI*() const  { return (const PackedRLI*) this; };
  140.  
  141.         //    Accessors
  142.     short                GetDSRefNum() {return fDSRefNum;};
  143.     DirDiscriminator    GetDiscriminator() { long offset = fDirectoryName.Length(); offset+=offset&1; return *(DirDiscriminator*)((char*)&fDirectoryName + offset); }
  144.     OSType                GetDirSignature() { DirDiscriminator dirDisc = this->GetDiscriminator();  return dirDisc.signature; }
  145.  
  146. };
  147.  
  148. inline CPackedRLI& CPackedRLI::operator =(RLI* theRLI) { OCEPackRLI(theRLI, *this, sizeof(CPackedRLI)); fDSRefNum = 0; return *this;};
  149.  
  150. //------------------------------------------
  151. //            C R e c o r d I D
  152. //--------------------------------------------
  153.  
  154. //    !!!!CAUTION!!!! : A CRecordID is binary compatable with the OCE defined RecordID structure.  
  155. //              A pointer to one of these can be use anywhere a RecordIDPtr is called for in
  156. //              OCE API. However be aware of the DANGER of casting RecordID's to be CRecordID's. 
  157. //              The class assumes that  fName and fType pointers point to buffers sufficient
  158. //              to hold the longest name or type allowed.  For example this means if you have 
  159. //              a RecordID that points into a packed DSSpec the you should not call SetName().
  160. //              Also note that the node number format of the RLI is assumed.
  161.  
  162.  
  163. //    The key chain likes packed rids small.... we humor it.
  164. #define kKeyChainPackedRIDSize 20
  165. typedef unsigned char KeyChainPackedRID[kKeyChainPackedRIDSize], *KeyChainPackedRIDPtr;
  166.  
  167.  
  168. class CRecordID {
  169. public:
  170.     CPackedRLI*        fRLI;
  171.     CreationID        fCID;
  172.     CRecordName*    fName;
  173.     CRecordType*    fType;
  174.         
  175.         //    space for these. 
  176. private:        
  177.     CPackedRLI        _fPackedRLI;
  178.     CRecordName        _fRecordName;        
  179.     CRecordType        _fRecordType;
  180.     
  181. public:
  182.     
  183.     //    Constructors
  184.     CRecordID();
  185.     
  186.     CRecordID(short dsRefNum, CreationID cid);        
  187.     CRecordID(short pcatDSRefNum,char* recName,char* recType);
  188.     CRecordID(short pcatDSRefNum,StringPtr recName,StringPtr recType);
  189.     
  190.     CRecordID(CRLI& rli,CRecordName& recordName,CRecordType& recordType);
  191.     
  192.     CRecordID(CRecordID& cRID);
  193.     CRecordID(PackedDSSpecPtr packedDSSpec);
  194.     CRecordID(short dsRefNum, PackedRecordID* packedRecordID);
  195.     
  196.     
  197.     //    Assignment Operators
  198.     CRecordID& operator =(CRecordID& cRID);
  199.     CRecordID& operator =(RecordID* rid);
  200.     CRecordID& operator =(PackedDSSpecPtr packedDSSpec) { this->SetFromPackedDSSpec(packedDSSpec); return *this;  };
  201.     
  202.      void            SetName(CRecordName& newName);
  203.      void            SetName(StringPtr newName);
  204.      void            SetType(short);
  205.      void            SetNodeNumber(long nodeNumber) { fRLI->fNodeNumber = nodeNumber; };
  206.      
  207.     PackedDSSpec**     PackDSSpec();
  208.     
  209.     KeyChainPackedRIDPtr    PackKeyChainRID(KeyChainPackedRIDPtr pRID);
  210.     
  211.     
  212.     //     Cast Operators
  213.     operator RecordID*() { return (RecordID*) this; };
  214.     operator const RecordID*() const  { return (const RecordID*) this; };
  215.  
  216.  
  217.     //    Accessors
  218.     CRecordName&    Name() { return _fRecordName; }
  219.     DNodeNum        Node() { return fRLI->fNodeNumber; };
  220.     AddrBlock        GetServerHint() { AddrBlock    nilAddrBlock = {0,0,0}; return nilAddrBlock;} ;
  221.     short            GetDSRefNum() {return _fPackedRLI.GetDSRefNum();};
  222.     
  223.     CDirectoryName&    DirName() {  return _fPackedRLI.fDirectoryName; }
  224.     OSType            DirectorySignature() { return _fPackedRLI.fDiscriminator.signature; };
  225.     
  226.     void            SetFromPackedDSSpec(PackedDSSpecPtr packedDSSpec);
  227.  
  228.  
  229.     OSErr     GetNameAndType();
  230.     OSErr     SetNameAndType( Boolean allowDups );
  231.     OSErr    Create(Boolean allowDuplicates=false);
  232.     OSErr    CreateAsAlias(CRecordID& origRID,Boolean allowDuplicate=false,long backPtrFlags = 0);
  233.     OSErr     Delete();
  234.     
  235.     OSErr    AddAsPseudoNym(Boolean allowDupliate=false);        // assumes pseudonym have same Type as record.
  236.     OSErr    DeletePseudoNym();        // assumes pseudonym have same Type as record.
  237.     
  238. private:
  239.     void    Initialize();
  240.  
  241. };
  242.  
  243.  
  244. inline void     CRecordID::SetType(short recTypeIndex) { _fRecordType = (RString*) OCEGetIndRecordType(recTypeIndex); fCID.source = 0; fCID.seq = 0;};
  245.  
  246.  
  247. inline void CRecordID::SetName(CRecordName& newName) { *fName = newName; };
  248. inline void CRecordID::SetName(StringPtr newName) { *fName = newName; };
  249. inline CRecordID::CRecordID() 
  250. {
  251.     this->Initialize();
  252. };
  253.  
  254.  
  255.  
  256. #endif __CRecordID__
  257.